var iDisplayStart=0,iDisplayLength=20,totalPageNumAll,totalPageNumD,totalPageNumA,pageNumAll=0,pageNumD=0,pageNumA=0,AllSearchValue='',DSearchValue='',ASearchValue='';
$(function(){
	//ajax全局设置
	$.ajaxSetup({
		timeout:30000,
		beforeSend: function(request) {
            request.setRequestHeader("X-AIRPORT-TOKEN", localStorage.getItem("oauth_token"));
        },
		error:function(xhr,status){
			layer.msg("网络连接已超时，请重新刷新！");
		}
	})
	//保存数据
	$('#specialTemDataSave').on('click',function(){
		var specialPartSelectedItem=$('#specialPartSelectedItem').find('li');
		var specialPresentSelectedItem=$('#specialPresentSelectedItem').find('li');
		var specialAirportItem=$("#specialAirportItem").find('li');
		var specialAirportSelectedItem=$("#specialAirportItem>div:eq(1)").find('li.airportSelectBK');
		var specialAirportInput=$("#specialAirport").val();
		var specialDepartInput=$("#specialDepart").val();
		var specialPresentInput=$("#specialPresent").val();
		var specialRank=$('#specialRank').find('span.specialLevelSeleted');
		if($("#specialTemName").val()==""){
			layer.msg('特情标题不能为空')
			return;
		}
		if($("#specialTemName").val().length>100){
			layer.msg('特情标题字数不要超过100!')
			return;
		}
		if($("#specialTemCon").val()==""){
			layer.msg('特情内容不能为空')
			return;
		}
		if(getByteLen($("#specialTemCon").val()).length>1024){
			layer.msg('特情内容字数不要超过1024字符!')
			return;
		}
		if(specialPartSelectedItem.length==0 && specialPresentSelectedItem.length==0){
			layer.msg('请关联部门或抄送人员');
			return;
		}
		if(specialDepartInput=="" && specialPresentInput==""){
			layer.msg('请确定选择好的关联部门或抄送人员');
			return;
		}
		if(specialRank.length==0){
			layer.msg('请选择特情等级');
			return;
		}
		/*if(specialAirportInput!=""){
			var reg = /^([0-9a-zA-Z]+[,]?)*$/;
			if(!reg.test(specialAirportInput)){
				layer.msg("您输入的关联的航班信息不符合规范！请按照正确的格式输入，如：RNG8888,EDG8888")
				return;
			}
		}*/
		var template={"id":null,"topic":$("#specialTemName").val(),"content":$("#specialTemCon").val(),"level":$('#specialRank').find('span.specialLevelSeleted').text()};
		var itemDeptList=[];
		var itemUserList=[];
		var itemFlightList=[];
		if(specialPartSelectedItem.length!=0){
			$.each(specialPartSelectedItem,function(i,n){
				itemDeptList.push({"id":null,"templateId":null,"subCode":$(n).attr('id'),"subName":$(n).text(),"subType":"1"});
				//itemDeptList.push({"id":null,"templateId":null,"roleCode":$(n).attr('roleCode'),"subCode":$(n).attr('subCode'),"subName2":specialSubString($(n).text()),"subName":$(n).attr('subName'),"subCode2":$(n).attr('roleCode'),"subType":"1"});
			})
		}
		if(specialPresentSelectedItem.length!=0 && specialPresentInput!=""){
			$.each(specialPresentSelectedItem,function(i,n){
				itemUserList.push({"id":null,"templateId":null,"subCode":$(n).attr('id'),"subName":$(n).text(),"subType":"2"});
			})
		}
		if(specialAirportInput!=""){
			var specialAirportInputArray=specialAirportInput.split(",")
			$.each(specialAirportInputArray,function(i,n){
					itemFlightList.push({"id":null,"templateId":null,"subCode":null,"subName":n,"subType":"3"});
			})
			/*if(specialAirportSelectedItem.length!=0){
				$.each(specialAirportInputArray,function(i,n){
					$.each(specialAirportSelectedItem,function(a,b){
						if(n==$(b).text()){
							itemFlightList.push({"id":null,"templateId":null,"subCode":$(b).attr('id'),"subName":$(b).text(),"subType":"3"});
							delete specialAirportInputArray[i];
						}
					})
				})
				if(specialAirportInputArray!="[]" && specialAirportInputArray.length!=0){
					$.each(specialAirportInputArray,function(i,n){
						if(n!=undefined && n!="undefined"){
							itemFlightList.push({"id":null,"templateId":null,"subCode":null,"subName":n,"subType":"3"});
						}
					})
				}
			}else{
				$.each(specialAirportInputArray,function(i,n){
					itemFlightList.push({"id":null,"templateId":null,"subCode":null,"subName":n,"subType":"3"});
				})
			}*/
		}
		var templetData={"template":template,"itemDeptList":itemDeptList,"itemUserList":itemUserList,"itemFlightList":itemFlightList,"loginName":localStorage.oauth_token};
		layer.confirm('您确认保存？',function(index){
			layer.close(index);
			$.ajax({
				type:'POST',
				url:baseURL+'/api/special/template/add',
				dataType:'json',
				contentType:"application/json",
				data:JSON.stringify(templetData),
				success:function(result){
					if(!result.flag){
						layer.msg("数据错误"+result.message)
					}else{
						layer.msg('保存成功',1,1);
						$("#specialAddForm").find("input,textarea,select").val("");
						window.location.href=baseURL+"/api/special/template/page/list?ouath_token="+localStorage.getItem("oauth_token");
					}
				}
			})
		})
	})
	
	var specialAddPart=function(){$.ajax({//部门
		type:'GET',
		url:baseURL+'/services/dept/listSSRDept',
		dataType:'json',
		success:function(result){
			if(result.errorcode=="1"){
        		  layer.msg("查询失败！");
        		  return;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
			var htmlPart="";
			var obj=result.results;
			function returnBack(obj){
				if(!obj) return;
				$.each(obj,function(i,n){
						if(this.subDepartmentList!=null && this.subDepartmentList!="[]" && this.subDepartmentList.length!=0){
							if(this.includeRole){
								htmlPart+="<li><span class='folder' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							}else htmlPart+="<li><span class='folder disabled c-999' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							returnBack(this.subDepartmentList)
							htmlPart+="</ul>";
						}else {
							if(this.includeRole){
								htmlPart+="<li><span class='file' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
							}else htmlPart+="<li><span class='file disabled c-999' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
						}
				})
				htmlPart+="</li>";
			}
			returnBack(obj)
			$('#specialPartItem').append(htmlPart)
			$('#specialPartItem').find('span:not(.disabled)').on('click',function(e){
				e.stopPropagation();
				$('#specialPartItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK');
				partSelectId=$(e.target).attr('id');
				partSelectText=$(e.target).text();
			})
			$('#specialPartSelectedItemAddBtn').on('click',function(e){
				e.stopPropagation()
				if(partSelectId=="" && partSelectText==""){
					layer.msg("请选择部门！")
					return false;
				}
				var specialPartSelectedItem=$('#specialPartSelectedItem').find('li');
				var flag=true;
				if(specialPartSelectedItem.length!=0){
					$.each(specialPartSelectedItem,function(i,n){
						if($(n).attr('id')==partSelectId){
							layer.msg('请不要重复添加')
							flag=false;
						}
					})
					if(flag){
						$('#specialPartSelectedItem').append("<li id='"+partSelectId+"' onclick=\"changePortSelect(this)\">"+partSelectText+"</li>");
					}
				}else {
					$('#specialPartSelectedItem').append("<li id='"+partSelectId+"' onclick=\"changePortSelect(this)\">"+partSelectText+"</li>");
				}
			})
			$("#specialPartSelectedItemShowBtn").on('click',function(e){
				$(e.target).parents("div.specialSelect").hide();
				inputPartHtml="";
				$.each($('#specialPartSelectedItem').find('li'),function(i,n){
					inputPartHtml+=$(n).text()+",";
				})
				$("#specialDepart").val(specialSubString(inputPartHtml))
			})
			$('#specialPartSelectedItemRemoveBtn').on('click',function(e){
					inputPartHtml="";
					e.stopPropagation();
					var specialPartRemoveItem=$('#specialPartSelectedItem').find('li.airportSelectBK');
					if(specialPartRemoveItem.length==0){
						return false;
					}
					if(specialPartRemoveItem.length!=0){
						$.each(specialPartRemoveItem,function(i,n){
							$(n).remove();
						})
					}
					$.each($('#specialPartSelectedItem').find('li'),function(i,n){
						inputPartHtml+=$(n).text()+",";
					})
					$("#specialDepart").val(specialSubString(inputPartHtml))
			})
			$("#specialPartSelectedItemHiddenBtn").on('click',function(){
				$("#specialDepart").val("")
				$('#specialPartSelectedItem').empty();
			})
			$("#specialPartItem").treeview({
				animated: "fast",
				collapsed: true,
				unique: true,
				//persist: "cookie",
				toggle: function() {
					//window.console && console.log("%o was toggled", this);
				}
			})
		}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}
	specialAddPart();
	//抄送人员
	var specialAddPresent=function(){$.ajax({
		type:'GET',
		url:baseURL+'/services/dept/listDept',
		dataType:'json',
		success:function(result){
			if(result.errorcode=="1"){
        		  layer.msg("查询失败！");
        		  return;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
			var htmlPart="";
			var obj=result.results;
			function returnBack(obj){
				if(!obj) return;
				$.each(obj,function(){
						if(this.subDepartmentList!=null && this.subDepartmentList!="[]" && this.subDepartmentList.length!=0){
							htmlPart+="<li><span class='folder' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							returnBack(this.subDepartmentList)
							htmlPart+="</ul>";
						}else {
							htmlPart+="<li><span class='file' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
						}
				})
				htmlPart+="</li>";
			}
			returnBack(obj)
			$('#specialPresentItem').append(htmlPart)
			$('#specialPresentItem').find('span').on('click',function(e){
				e.stopPropagation();
				$('#specialPresentItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK')
				$('#specialPresentSelectedAllItem').empty();
				specialPresent($(e.target).attr('id'));
			})
			$("#specialPresentSelectedItemShowBtn").on('click',function(e){
				$(e.target).parents("div.specialSelect").hide();
				inputPresentHtml="";
				if($('#specialPresentSelectedItem').find('li').length!=0){
					$.each($('#specialPresentSelectedItem').find('li'),function(i,n){
						inputPresentHtml+=$(n).text()+",";
					})
					$("#specialPresent").val(specialSubString(inputPresentHtml))
				}else $("#specialPresent").val("");
				$("#specialPresentSelectedAllItem").find('li').removeClass("airportSelectBK");
			})
			$('#specialPresentSelectedItemAddBtn').on('click',function(e){
					e.stopPropagation()
					var specialPresentSelectedItem=$('#specialPresentSelectedItem').find('li');
					var specialPresentSelectedAllItem=$('#specialPresentSelectedAllItem').find('li.airportSelectBK');
					if(specialPresentSelectedAllItem.length==0){
						layer.msg("请选择人员！")
						return false;
					}
					var flag=true;
					if(specialPresentSelectedItem.length!=0){
						$.each(specialPresentSelectedAllItem,function(i,n){
							$.each(specialPresentSelectedItem,function(o,p){
								if($(n).attr('id')==$(p).attr('id')){
									layer.msg('请不要重复添加');
									flag=false;
								}
							})
						})
						if(flag){
							$.each(specialPresentSelectedAllItem,function(i,n){
								$('#specialPresentSelectedItem').append("<li id='"+$(n).attr('id')+"' onclick=\"changePortSelect(this)\">"+$(n).text()+"</li>");
							})
						}
					}else {
						$.each(specialPresentSelectedAllItem,function(i,n){
							$('#specialPresentSelectedItem').append("<li id='"+$(n).attr('id')+"' onclick=\"changePortSelect(this)\">"+$(n).text()+"</li>");
						})
					}
			})
			$("#specialPresentItem").treeview({
				animated: "fast",
				collapsed: true,
				unique: true,
				//persist: "cookie",
				toggle: function() {
					//window.console && console.log("%o was toggled", this);
				}
			})
		}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}
	specialAddPresent();
	//相关人员
	var specialPresent=function(id){
		$.ajax({    
		type:'GET',
		url:baseURL+'/services/dept/listEmployee/'+id,
		dataType:'json',
		contentType:"application/json",
		success:function(result){
			if(result.errorcode=="1"){
          		  layer.msg("查询失败！");
          		  return false;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
				var html="";
				var inputPresentHtml,inputPresentHtml_1;
				if(result.results!=null && result.results.length!=0 && result.results!="[]"){
					$.each(result.results,function(i,n){
						html+="<li id='"+n.id+"' onclick=\"changePortSelect(this)\">"+n.empName+"</li>"
					})
					$('#specialPresentSelectedAllItem').html(html);
				}else $('#specialPresentSelectedAllItem').html("<div class='text-c mt-20'>无数据</div>");
				$('#specialPresentSelectedItemRemoveBtn').on('click',function(e){
						inputPresentHtml="";
						e.stopPropagation();
						var specialPartRemoveItem=$('#specialPresentSelectedItem').find('li.airportSelectBK');
						var specialPartRemoveAllItem=$('#specialPresentSelectedAllItem').find('li');
						$.each(specialPartRemoveAllItem,function(i,n){
							$.each(specialPartRemoveItem,function(o,p){
								if($(n).attr('id')==$(p).attr('id')){
									$(n).removeClass("airportSelectBK");
								}
							})
						})
						if(specialPartRemoveItem.length==0){
							return false;
						}
						if(specialPartRemoveItem.length!=0){
							$.each(specialPartRemoveItem,function(i,n){
								$(n).remove();
							})
						}
				})
				$("#specialPresentSelectedItemHiddenBtn").on('click',function(){
					$("#specialPresent").val("")
					$('#specialPresentSelectedItem').empty();
					$('#specialPresentSelectedAllItem').find('li').removeClass("airportSelectBK");
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
}
	
	/*var specialAddPart=function(){$.ajax({//部门
		type:'GET',
		url:baseURL+'/services/dept/listDept',
		dataType:'json',
		success:function(result){
			if(result.errorcode=="1"){
        		  layer.msg("查询失败！");
        		  return;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
			var htmlPart="";
			var obj=result.results;
			function returnBack(obj){
				if(!obj) return;
				$.each(obj,function(){
					if(this.subDepartmentList!=null && this.subDepartmentList!="[]" && this.subDepartmentList.length!=0){
						htmlPart+="<li><span class='folder' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
						returnBack(this.subDepartmentList)
						htmlPart+="</ul>";
					}else {
						htmlPart+="<li><span class='file' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
					}
				})
				htmlPart+="</li>";
			}
			returnBack(obj)
			$('#specialPartItem').append(htmlPart)
			$('#specialPresentItem').append(htmlPart)
			$('#specialPartItem').find('span').on('click',function(e){
				e.stopPropagation();
				$('#specialPartItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK')
				$('#specialPartSelectedAllItem').empty();
				specialPart($(e.target).attr('id'),$(e.target).text());
			})
			//人员
			$('#specialPresentItem').find('span').on('click',function(e){
				e.stopPropagation();
				$('#specialPresentItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK')
				$('#specialPresentSelectedAllItem').empty();
				specialPresent($(e.target).attr('id'));
			})
			$("#specialPartItem,#specialPresentItem").treeview({
				animated: "fast",
				collapsed: true,
				unique: true,
				//persist: "cookie",
				toggle: function() {
					//window.console && console.log("%o was toggled", this);
				}
			})
		}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}
	specialAddPart();
	//相关角色
	var specialPart=function(id,partName){
		$.ajax({    
		type:'GET',
		url:baseURL+'/services/dept/listRole/'+id,
		dataType:'json',
		contentType:"application/json",
		success:function(result){
			if(result.errorcode=="1"){
          		  layer.msg("查询失败！");
          		  return false;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
				var html="";
				var inputPartHtml_1,inputPartHtml;
				if(result.results!=null && result.results.length!=0 && result.results!="[]"){
					$.each(result.results,function(i,n){
						html+="<li roleCode='"+n.code+"'>"+n.name+"<span class='ml-5 c-red'>("+partName+")</span>"+"</li>"
					})
					$('#specialPartSelectedAllItem').html(html);
				}else $('#specialPartSelectedAllItem').html("<div class='text-c mt-20'>无数据</div>");
				$('#specialPartSelectedAllItem').find('li').on('click',function(e){
					inputPartHtml="";
					e.stopPropagation();
					$(e.target).toggleClass("commonSelectColor");
					var specialPartSelectedItem=$('#specialPartSelectedAllItem').next().find('li');
					var flag=true;
					if(specialPartSelectedItem.length!=0){
						$.each(specialPartSelectedItem,function(i,n){
							if($(n).attr('roleCode')==$(e.currentTarget).attr('roleCode')){
								layer.msg('请不要重复添加')
								flag=false;
							}
						})
						if(flag){
							$('#specialPartSelectedAllItem').next().append("<li subCode='"+id+"' subName='"+partName+"' roleCode='"+$(e.currentTarget).attr('roleCode')+"'>"+$(e.currentTarget).html()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
						}
					}else {
						$('#specialPartSelectedAllItem').next().append("<li subCode='"+id+"' subName='"+partName+"' roleCode='"+$(e.currentTarget).attr('roleCode')+"'>"+$(e.currentTarget).html()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
					}
					$.each($('#specialPartSelectedItem').find('li'),function(i,n){
						inputPartHtml+=specialSubString($(n).text())+",";
					})
					$("#specialDepart").val(specialSubString(inputPartHtml))
					$('.iconDelete').on('click',function(ev){
						ev.stopPropagation();
						inputPartHtml_1="";
						$(ev.target).parent().remove();
						$.each($("#specialPartSelectedItem").find('li'),function(i,n){
							inputPartHtml_1+=specialSubString($(n).text())+",";
						})
						$("#specialDepart").val(specialSubString(inputPartHtml_1));
					})
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
}
	//相关人员
	var specialPresent=function(id){
		$.ajax({    
		type:'GET',
		url:baseURL+'/services/dept/listEmployee/'+id,
		dataType:'json',
		contentType:"application/json",
		success:function(result){
			if(result.errorcode=="1"){
          		  layer.msg("查询失败！");
          		  return false;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
				var html="";
				var inputPresentHtml,inputPresentHtml_1;
				if(result.results!=null && result.results.length!=0 && result.results!="[]"){
					$.each(result.results,function(i,n){
						html+="<li id='"+n.id+"'>"+n.empName+"</li>"
					})
					$('#specialPresentSelectedAllItem').html(html);
				}else $('#specialPresentSelectedAllItem').html("<div class='text-c mt-20'>无数据</div>");
				$('#specialPresentSelectedAllItem').find('li').on('click',function(e){
					e.stopPropagation();
					inputPresentHtml="";
					$(e.target).toggleClass("commonSelectColor");
					var specialPartSelectedItem=$('#specialPresentSelectedAllItem').next().find('li');
					var flag=true;
					if(specialPartSelectedItem.length!=0){
						$.each(specialPartSelectedItem,function(i,n){
							if($(n).attr('id')==$(e.currentTarget).attr('id')){
								layer.msg('请不要重复添加')
								flag=false;
							}
						})
						if(flag){
							$('#specialPresentSelectedAllItem').next().append("<li id='"+$(e.currentTarget).attr('id')+"'>"+$(e.currentTarget).text()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
						}
					}else {
						$('#specialPresentSelectedAllItem').next().append("<li id='"+$(e.currentTarget).attr('id')+"'>"+$(e.currentTarget).text()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
					}
					$.each($("#specialPresentSelectedItem").find('li'),function(i,n){
						inputPresentHtml+=$(n).text().substring(0,$(n).text().length-1)+",";
					})
					$("#specialPresent").val(specialSubString(inputPresentHtml))
					$('.iconDelete').on('click',function(ev){
						ev.stopPropagation();
						inputPresentHtml_1="";
						$(ev.target).parent().remove();
						$.each($("#specialPresentSelectedItem").find('li'),function(i,n){
							inputPresentHtml_1+=$(n).text().substring(0,$(n).text().length-1)+",";
						})
						$("#specialPresent").val(specialSubString(inputPresentHtml_1));
					})
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
}
*/
	//航班
	var specialAirport=function(type,page,obj){
		$("#specialAirportLoad").show();
		$.ajax({   
		type:'GET',
		url:baseURL+'/api/special/template/listFlight?type='+type+'&flightNo='+obj+'&iDisplayStart='+iDisplayLength*page+'&iDisplayLength='+iDisplayLength,
		dataType:'json',
		success:function(result){
			$("#specialAirportLoad").hide();
			var fligthAll="";
			if(result.results.length==0){
				$("#airportTypeAllList").empty().html("<li class='disabled'>没有数据</li>");
			}else{
				totalPageNumAll=Math.floor(result.totalcount/iDisplayLength);
				$.each(result.results,function(i,n){
					fligthAll+="<li class='text-c airportBK radius' id='"+n.flightId+"'>"+n.flightNo+"</li>";
				})
				$("#airportTypeAllList").html(fligthAll);
				$('#airportTypeAllList').find('li').on('click',function(e){
					e.stopPropagation();
					var fligthInputHtml="",specialAirportInputArray=[],specialAirportInput="";
					$(e.target).toggleClass("airportSelectBK");
					specialAirportInput=$("#specialAirport").val();
					if($(e.target).hasClass("airportSelectBK")){
						if(specialAirportInput.indexOf($(e.target).text())!=-1){
							layer.msg('请不要重复添加！')
						}else{
							if(specialAirportInput!=""){
								specialAirportInput+=","+$(e.target).text();
							}else specialAirportInput+=$(e.target).text();
							$("#specialAirport").val(specialAirportInput);
						}
					}else{
						specialAirportInputArray=specialAirportInput.split(",")
						$.each(specialAirportInputArray,function(i,n){
							if(n==$(e.target).text()){
								delete specialAirportInputArray[i]
							}
						})
						if(specialAirportInputArray!="[]" && specialAirportInputArray.length!=0){
							$.each(specialAirportInputArray,function(i,n){
								if(n!=undefined && n!="undefined"){
									fligthInputHtml+=n+",";
								}
							})
						}
						$("#specialAirport").val(specialSubString(fligthInputHtml));
					}
				})
				$('#specialAirportSelectedItemShowBtn').on('click',function(e){
					$(e.target).parents("div.specialSelect").hide();
				})
				$("#specialAirportSelectedItemHiddenBtn").on('click',function(){
					$("#specialAirport").val("");
					$('#airportTypeAllList').find('li').removeClass("airportSelectBK");
				})
			}
		
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}

	specialAirport("All",0,"");
	$('.nextPagitionAll').on('click',function(e){
		e.stopPropagation();
		++pageNumAll;
		if(pageNumAll>totalPageNumAll){
			pageNumAll=totalPageNumAll
			return;
		}else{
			if($(".searchTemplet").val()!=""){
				specialAirport("All",pageNumAll,$(".searchTemplet").val());
			}else specialAirport("All",pageNumAll,'');
		}
	})
	$('.prevPagitionAll').on('click',function(e){
		e.stopPropagation();
		--pageNumAll;
		if(pageNumAll<=-1){
			pageNumAll=0;
			return;
		}else{
			if($(".searchTemplet").val()!=""){
				specialAirport("All",pageNumAll,$(".searchTemplet").val());
			}else specialAirport("All",pageNumAll,'');
		}
	})
	$('#specialAirport').on('keyup',function(e){
		$.each($('#specialAirportItem').find('li.airportSelectBK'),function(i,n){
			if($(e.target).val().indexOf($(n).text())==-1){
				$(n).removeClass('airportSelectBK');
			}
		})
		specialAirport("All",0,$("#specialAirport").val());
	})
	
	$('.doSearch').on('click',function(e){
		specialAirport("All",0,$(".searchTemplet").val());
	})
  
	function specialSubString(args){
		return args.substring(0,args.length-1);
	}
	
	
	
	
	
	$.ajax({   //特情等级
		type:'GET',
		url:baseURL+'/api/special/template/listLevel',
		dataType:'json',
		success:function(result){
			if(!result.flag){
				layer.msg('数据出错')
			}else{
				var html="";
				$.each(result.results,function(i,n){
					if(n.dictItemName=="T1"){
						html+="<span class='specialLevel_f' style='background:#29c6ef'>"+n.dictItemName+"</span>";
					}else if(n.dictItemName=="T2"){
						html+="<span class=' ' style='background:#4784c3'>"+n.dictItemName+"</span>";
					}else if(n.dictItemName=="T3"){
						html+="<span class=' ' style='background:#ffc001'>"+n.dictItemName+"</span>";
					}else if(n.dictItemName=="T4"){
						html+="<span class=' ' style='background:#ff6600'>"+n.dictItemName+"</span>";
					}else if(n.dictItemName=="T5"){
						html+="<span class='specialLevel_l' style='background:#da0000'>"+n.dictItemName+"</span>";
					}
				})
				$('#specialRank').append(html);
				$("#specialRank").find('span').on('click',function(e){
					e.stopPropagation();
					$("#specialRank").find('span').removeClass("specialLevelSeleted");
					$(e.target).addClass("specialLevelSeleted");
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	
	var isMouse=true;
	$('.specialSelectInput').on('click',function(e){
		e.stopPropagation();
		$(e.target).attr('flag','false')
		$.each($('.specialSelectInput'),function(i,n){
			if($(n).attr('flag')=="true"){
				$(n).next().hide();
			}else $(n).attr('flag','true')
		})
		$(e.target).next().toggle();
		$(e.target).next().on('mouseleave',function(ev){
			ev.stopPropagation();
			$(e.target).next().hide();
			isMouse=true;
		})
		$(e.target).next().on('mouseover',function(ev){
			isMouse=false;
		})
	})
	$('.specialSelectInput').on('blur',function(e){
		if(isMouse){
			$(e.target).next().hide();
		}
	})
});
function changePortSelect(obj){
	$(obj).toggleClass("airportSelectBK");
}
//获取字符串长度（汉字算两个字符，字母数字算一个）
function getByteLen(val) {
  var len = 0;
  for (var i = 0; i < val.length; i++) {
    var a = val.charAt(i);
    if (a.match(/[^\x00-\xff]/ig) != null) {
      len += 2;
    }
    else {
      len += 1;
    }
  }
  return len;
}